<?php
class WebLink
{
	public $Table="weblink";
	public $WebLinkID;
	public $WebLinkName;
	public $WebLink;
	public $Pos;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where WebLinkID='".$id."'";
		$row=$ob->singleData($sql);
		$this->WebLinkID=$row['WebLinkID'];
		$this->WebLinkName=$row['WebLinkName'];
		$this->WebLink=$row['WebLink'];
		$this->Pos=$row['Pos'];
	}
	function getTable($dk)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	function travel($dk)
	{
		$arr=array();
		$data=$this->getTable($dk);
		for($i=0;$i<count($data);$i++)
			array_push($arr,$data[$i]['WebLinkID']);
		return $arr;
	}
	function insert($conn)
	{
		$ob=new ClassConnect();
		$this->WebLinkID=$ob->getNextId($this->Table,"WebLinkID");
		$field=array("WebLinkID","WebLinkName","WebLink","Pos");
		$value=array($this->WebLinkID,$this->WebLinkName,$this->WebLink,$this->Pos);
		return $ob->insertData($conn,$this->Table,$field,$value);
	}
	function update($conn)
	{
		$ob=new ClassConnect();
		$field=array("WebLinkID","WebLinkName","WebLink","Pos");
		$value=array($this->WebLinkID,$this->WebLinkName,$this->WebLink,$this->Pos);
		$where="WebLinkID = '".$this->WebLinkID."'";
		
		return $ob->updateData($conn,$this->Table,$field,$value,$where);			
	}
	function save($conn)
	{
		$obj=new WebLink();
		$obj->loadByKey($this->WebLinkID);
		if($obj->WebLinkID=="")
			$this->insert($conn);
		else
			$this->update($conn);
	}
	function delete($conn)
	{
		$ob=new ClassConnect();		
		$where="WebLinkID = '".$this->WebLinkID."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}
	function getNextPos()
	{
		$ob=new ClassConnect();
		$sql="SELECT max(Pos) as max FROM `".$this->Table."`";
		$row=$ob->singleData($sql);
		$max=$row['max'];
		return $max + 1;
	}
	function updatePos($conn)
	{
		$ob=new ClassConnect();
		$field=array("WebLinkID","Pos");
		$value=array($this->WebLinkID,$this->Pos);
		$where="WebLinkID = '".$this->WebLinkID."'";
		$ob->updateData($conn,$this->Table,$field,$value,$where);
	}
}
?>
